package com.example.springpethospital.entity.examination.po;

import com.example.springpethospital.common.exception.PetHospitalException;
import com.example.springpethospital.entity.examination.po.ExaminationPaperPO.ExaminationPaperQuestion;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExaminationPO {

    private Integer id;

    /**
     * 考试title
     */
    private String title;

    /**
     * 试卷id
     */
    private Integer paperId;

    /**
     * 开始时间
     */
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    private LocalDateTime endTime;

    /**
     * 考试人员id
     */
    private List<Integer> studentIds;

    public void check(boolean update) {
        List<String> errorMessage = new LinkedList<>();
        if (update && id == null) {
            errorMessage.add("主键id不可为空");
        }
        if (StringUtils.isEmpty(title)) {
            errorMessage.add("考试标题不可为空");
        }
        if (paperId == null) {
            errorMessage.add("考试试卷不可为空");
        }
        if (startTime == null || endTime == null) {
            errorMessage.add("考试开始时间和结束时间都不可为空");
        }
        if (CollectionUtils.isEmpty(studentIds)) {
            errorMessage.add("考试参与学生不可为空");
        }
        if (CollectionUtils.isNotEmpty(errorMessage)) {
            throw new PetHospitalException(String.join( "|", errorMessage));
        }
    }

}
